let routes =  [
  { 
    path: '/', 
    name: 'layout', 
    // component: () => import("@/views/layout"),
    component: 'layout',
    redirect: { name: 'home'},
    children: [
      { path: '/home', name:'homeIndex', component: 'Home/index'},
      { path: '/system/user', name:'homeIndex', component: 'Home/index'},
    ]
  },
  {
    path: '/login',
    name: 'login',
    // component: () => import("@/views/Login/index"),
    component: 'Login/index',
  },
  {
    path: '*',
    redirect: { name: 'home'}
  }
]

// 获取路由信息组件
let getRoutes = function() {
  //自动生成路由
  createRoutes(routes)
  return routes // 重定向
}

// 自动生成路由(递归)
function createRoutes (arr) {
  for (let i = 0; i < arr.length; i++) {
    if(!arr[i].component) return 
    // 自动生成component
    let componentFun = import(`@/views/${arr[i].component}`)
    arr[i].component = () => componentFun
    if(arr[i].children && arr[i].children.length > 0) {
      createRoutes(arr[i].children)
    }
  }
}

export default getRoutes()